package logic

import (
	"context"
	"my-zero-tiktok/apps/user/pb/pb"
	"my-zero-tiktok/apps/user/rpc/internal/svc"
	"my-zero-tiktok/common/xerr"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
	return &GetUserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetUserList 批量获取用户
func (l *GetUserListLogic) GetUserList(in *pb.IDListRequest) (*pb.UserListResponse, error) {
	users, err := l.svcCtx.UserModel.UserList(l.ctx, in.UserIds)
	if err != nil {
		return nil, xerr.New(xerr.UserGetListError)
	}

	List := make([]*pb.User, len(users))
	for i, u := range users {
		List[i] = &pb.User{Id: u.Id, Name: u.Name}
	}
	return &pb.UserListResponse{List: List}, nil
}
